package com.jinxin.platform.cdsideparkmgr.controller;

import com.jinxin.platform.base.api.annotation.*;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.annotation.UnLoginForUser;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdsideparkmgr.bean.bo.PushInfo;
import com.jinxin.platform.cdsideparkmgr.service.ICdsideparkmageDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author 那个男人
 * @Date 2022/9/19 11:07
 * @Version 1.0
 */
@APCOSApi(value = "路边停车管理中间件接口", developers = {"lingnan"}, description = "路边停车管理中间件接口")
@RestController
@RequestMapping("/cdsideparkmgr/device")
@Slf4j
public class DeviceController {
    @Autowired
    private ICdsideparkmageDeviceService deviceService;

//    @UnLoginForUser
//    @APCOSApiOperation(value = "设备心跳推送(低位)", developers = {"lingnan"}, description = "设备心跳推送(低位)",
//            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
//    @PostMapping("/heartbeatPush")
//    public JsonResult heartbeatPush(@RequestBody Map<String,Object> param){
//        return deviceService.heartbeatPush(param);
//    }
//
//
    @UnLoginForUser
    @APCOSApiOperation(value = "推送业务识别结果(低位)", developers = {"lingnan"}, description = "推送业务识别结果(低位)",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/resultPush")
    public JsonResult resultPush(@RequestBody PushInfo pushInfo){
        log.info("中间件推送");
        return deviceService.pushResult(pushInfo);
    }

//    @UnLoginForUser
//    @APCOSApiOperation(value = "设备心跳推送(高位)", developers = {"lingnan"}, description = "设备心跳推送(高位)",
//            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
//    @PostMapping("/heartbeatPush4H")
//    public JsonResult heartbeatPush4H(@RequestBody Map<String,Object> param){
//        return deviceService.heartbeatPushForHeight(param);
//    }

    @UnLoginForUser
    @APCOSApiOperation(value = "推送业务识别结果(高位)", developers = {"lingnan"}, description = "推送业务识别结果(高位)",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/resultPush4H")
    public JsonResult resultPush4H(@RequestBody Map<String,Object> param){
        return deviceService.resultPushForHeight(param);
    }

    @APCOSApiOperation(value = "手动抓拍", developers = {"lingnan"}, description = "手动抓拍",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/snap")
    public JsonResult snap(@RequestParam(name = "sn") String sn){
        return deviceService.snap(sn);
    }

    @APCOSApiOperation(value = "获取设备实时视频", developers = {"lingnan"}, description = "获取设备实时视频",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/queryVideoUrl")
    public JsonResult queryVideoUrl(@RequestParam(name = "sn") String sn){
        return deviceService.queryVideoUrl(sn);
    }

//    @APCOSApiOperation(value = "获取设备实时视频(mjpeg)", developers = {"lingnan"}, description = "获取设备实时视频(mjpeg)",
//            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
//    @GetMapping("/queryMjpegVideoUrl")
//    public JsonResult queryMjpegVideoUrl(@RequestParam(name = "sn") String sn){
//        return deviceService.queryMjpegVideoUrl(sn);
//    }

    @APCOSApiOperation(value = "根据项目ID获取相机视频地址列表(相机)", developers = {"lingnan"}, description = "根据项目ID获取相机视频地址列表(相机)",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @APCOSApiRequests({
            @APCOSApiRequest(name = "projectId",value = "相机项目id",fieldType = APCOSApiConstans.FIELD_TYPE_GN,required = true,
                    reqType = APCOSApiConstans.REQ_TYPE_BODY,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "32",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
            @APCOSApiRequest(name = "cameraName",value = "高低位相机名称",fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    reqType = APCOSApiConstans.REQ_TYPE_BODY,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50",matchType = APCOSApiConstans.MATCH_TYPE_LIKE),
            @APCOSApiRequest(name = "cameraArea",value = "高低位相区域名称",fieldType = APCOSApiConstans.FIELD_TYPE_GN,required = true,
                    reqType = APCOSApiConstans.REQ_TYPE_BODY,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "32",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
    })
    @APCOSApiResponses({
            @APCOSApiResponse(name = "status", value = "状态码", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM, lenth = "10,0"),
            @APCOSApiResponse(name = "msg", value = "提示信息", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR, lenth = "100"),
            @APCOSApiResponse(name = "data", value = "返回地址列表(数组)", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR, lenth = "2000",remark = "返回示例:[{\"sn\":\"fd46e237-20bf5c24\",\"url\":\"ws://118.121.200.15:37685/ws.flv\"}]"),

    })
    @GetMapping("/listVideoUrlList")
    public JsonResult listVideoUrlList(@RequestParam(name = "projectId") String projectId,@RequestParam(name = "cameraName",required = false) String cameraName,
            @RequestParam(name = "cameraArea",required = false) String cameraArea){
        return deviceService.listVideoUrlList(projectId,cameraName,cameraArea);
    }

    @APCOSApiOperation(value = "根据设备序列号获取泊位情况", developers = {"lingnan"}, description = "根据设备序列号获取泊位情况",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @APCOSApiRequests({
            @APCOSApiRequest(name = "sn",value = "相机序列号",fieldType = APCOSApiConstans.FIELD_TYPE_GN,required = true,
                    reqType = APCOSApiConstans.REQ_TYPE_URL,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
            @APCOSApiRequest(name = "page",value = "页码,最小值1,可不传",fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    reqType = APCOSApiConstans.REQ_TYPE_URL,dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "5,0",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
            @APCOSApiRequest(name = "limit",value = "每页条数,最大值1000,可不传",fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    reqType = APCOSApiConstans.REQ_TYPE_URL,dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "5,0",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
    })
    @APCOSApiResponses({
            @APCOSApiResponse(name = "status", value = "状态码", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM, lenth = "10,0"),
            @APCOSApiResponse(name = "msg", value = "提示信息", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR, lenth = "100"),
            @APCOSApiResponse(name = "data", value = "返回数据", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_OBJ),
            @APCOSApiResponse(name = "data.total", value = "泊位总数", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "5,0"),
            @APCOSApiResponse(name = "data.berths", value = "泊位列表", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_ARR),
            @APCOSApiResponse(name = "data.berths.parkingCode", value = "车场编号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.berths.parkingName", value = "车场名称", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.berths.deviceSn", value = "设备序列号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.berths.berthCode", value = "泊位号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.berths.berthState", value = "泊位状态(0:空闲,1:使用中)", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.berths.plateNumber", value = "车牌号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.berths.plateColor", value = "车牌颜色(0:未知;1:蓝色;2:黄色;3:白色;4:黑色;5:绿色)", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.berths.timeIn", value = "驶入时间(单位:秒)", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "10,0"),

    })
    @GetMapping("/queryStallStatus")
    public JsonResult queryStallStatus(@RequestParam(name = "sn") String sn,
                                       @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit){
        return deviceService.queryStallStatus(sn,page,limit);
    }

}
